﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NuMetaheuristics.Utility
{
    public class PromptSelection<T>
    {
        public T SelectOneOf(IEnumerable<T> items, string prompt)
        {
            int selection = 0;
            Console.WriteLine(prompt);

            for (int i = 0; i < items.Count(); i++)
            {
                Console.WriteLine("{0}. {1}", i, items.ElementAt(i).ToString());
            }

            while (!Int32.TryParse(Console.ReadLine(), out selection))
            {
                Console.WriteLine("Invalid selection");
                Console.WriteLine(prompt);
            }
            Console.WriteLine();
            Console.WriteLine("Selected {0}", items.ElementAt(selection));
            Console.WriteLine();
            
            return items.ElementAt(selection);
        }
    }
}
